﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;

namespace GenerateDictionary
{
    public class PerformanceCount
    {
        private List<PerformanceCounter> pc;
        private PerformanceCounterCategory cat;
        private List<string> instances;
        private Dictionary<string, float> cs;

        public PerformanceCount()
        {
            pc = new List<PerformanceCounter>();
            

            
            cat = new PerformanceCounterCategory("Processor Information");
            instances = new List<string>();
            instances.AddRange(cat.GetInstanceNames());
            foreach (var s in instances)
            {
                var n = new PerformanceCounter("Processor Information", "% Processor Time");
                n.InstanceName = s;
                pc.Add(n);
            }
            cs = new Dictionary<string, float>();

        }
        

        public Dictionary<string, float> GetnextValues(){
            GC.Collect();
            cs.Clear();
            for(int i=0;i<pc.Count();i++)
            {
                cs.Add((pc[i].InstanceName), pc[i].NextValue());
            }

            return cs;          

                
                
        }
    }
}
